package com.jiaquyun.jcps.ui.mine

import android.app.Activity
import android.content.Intent
import androidx.lifecycle.Observer
import com.jiaquyun.jcps.R
import com.jiaquyun.jcps.base.ViewModeActivity
import com.jiaquyun.jcps.mode.vm.MineViewModel
import com.lemlin.network.HttpServiceStatus
import kotlinx.android.synthetic.main.activity_user_info.*

class UserInfoActivity : ViewModeActivity<MineViewModel>() {

    companion object {
        fun open(activity: Activity) {
            val intent = Intent(activity, UserInfoActivity::class.java)
            activity.startActivity(intent)
        }
    }

    override fun viewModel(): MineViewModel {
        return createViewModel()
    }

    override val layoutResId: Int
        get() = R.layout.activity_user_info

    override fun stateBar(): StatusBar {
        return StatusBar(isLightMode = true, color = R.color.colorWhite, view = flUserInfoBar)
    }

    override fun initView() {
        ivUserInfoBack.setOnClickListener {
            finish()
        }
    }

    override fun initData() {
        viewModel.userInfo()
    }

    override fun initViewMode() {
        viewModel.userInfoLiveData.observe(this, Observer { response ->
            if (response.statusCode == HttpServiceStatus.Status.FAILURE)
                toast(response.statusTip)
            if (response.statusCode == HttpServiceStatus.Status.SUCCESS) {
                response.httpData?.data?.let {
                    tvUserInfoName.text = it.nickname
                    tvUserInfoJob.text = it.job_number
                    tvUserInfoPhone.text = it.mobile
                    tvUserInfoCardId.text = it.id_number
                    tvUserInfoPayMode.text =
                        if (it.cash_type == 1) "微信支付" else if (it.cash_type == 2) "支付宝支付" else "银行卡支付"
                    tvUserInfoPayAccount.text = it.pay_account
                }
            }
        })
    }
}